/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Compras;
import Controlador.Bean.Almacen.Almacen;
import Controlador.Bean.Almacen.ProdxSolicitudMovimiento;
import Controlador.Bean.Almacen.SolicitudMovimiento;
import Controlador.Bean.Compras.ProductoxOrden;
import Controlador.Bean.Compras.Solicitud;
import gui.General.Main;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableRowSorter;



/**
 *
 * @author LiziTa
 */
public class PanelSolOrdenAlm extends javax.swing.JInternalFrame {

    /**
     * Creates new form PanelSolOrdenAlm
     */
    PanelSolOrdenAlm.TableModel tb;
    
   public TableModel tb2;
    String estado;
    Date today;
    String id;
    String id2;
      public List<Almacen> almacen;
       public List<Solicitud> orden;
   public  String cmbor;
      
        public PanelSolOrdenAlm() {
             
            
      today = new Date();
        initComponents();
        initComp();
//         TableRowSorter<TableModel> sorter  = new TableRowSorter<TableModel>((TableModel) tblOrden.getModel());
//         tblOrden.setRowSorter(sorter);
        
    }
        
        
        private static PanelSolOrdenAlm myoc=null;
   
    
    
    public static PanelSolOrdenAlm getInstance() {
         if(myoc == null){
                       myoc = new PanelSolOrdenAlm();    
            Main.getDesktop().add(myoc); 
            myoc.setVisible(true);
               myoc.toFront();           
                    }
                    else{
                        if (myoc.isClosed()|| !myoc.isVisible()) {
                                myoc = new PanelSolOrdenAlm(); 
                                Main.getDesktop().add(myoc);
                                myoc.toFront();
                                myoc.setVisible(true);
                        }
                        else
                            myoc.toFront();
                    }
               
        
                return myoc;
    }
    

       private void initComp() {
        // tb = new PanelSolOrdenAlm.TableModel();
             
         tb2 = new TableModel();
     tblOrden.setModel(tb2);
tblOrden.setRowSelectionAllowed(true);
         
        today = new Date();
         almacen=Controlador.Service.Almacen.GestionAlmacenes.obtenerAlmacenes();
                
         orden=Controlador.Service.Compras.GestionCompra.obtenerOrdenMov();
         
           
        tblOrden.setDefaultRenderer(JButton.class, new PanelSolOrdenAlm.MiRender());
        tblOrden.setDefaultEditor( JButton.class, new PanelSolOrdenAlm.MiEditor());
           txtCapacidad.setVisible(false);
           txtCantidad.setVisible(false);
    }

       public class MiRender implements TableCellRenderer {
        // Este metodo indica como debe de pintarse el elemento en la fila row, en la columna column
        // que esta en la tabla table y tiene el color dado por el objeto.
        @Override
        public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) {    
            // como el boton y el calendario son componentes esto se vale.
            return (JComponent)table.getValueAt(row, column);
        }
     }
       
       public class MiEditor extends AbstractCellEditor implements TableCellEditor {
         private Boolean currentValue;
         @Override
         public Object getCellEditorValue()
         {
            return currentValue;
         }
         //El editor usara el propio componente. Para que funcione la celda en el modelo debe ser editable.
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
         {
           return (JComponent) value;// la tabla solo debe tener componentes graficos
         }
     }
    
       public void actualizarTable(String id){
       tb2.actualizarTabla2(id);
       }
             
      List<ProductoxOrden> data = Controlador.Service.Compras.GestionCompra.FiltroSolAlmacen(cmbor);
       class TableModel extends AbstractTableModel{
              
        //Two arrays used for the table data
        String[] columnNames = {"Producto", "Codigo", "Precio", "Cantidad", "Subtotal"};
                    
      
//        SolicitudMovimiento sm= Controlador.Service.Almacen.GestionAlmacenes.obtenerSolicitudMovimientoxIdMovimiento(id2);
        
        public void actualizarTabla(){
            data = Controlador.Service.Compras.GestionCompra.FiltroSolAlmacen(txtOrden.getText());
            fireTableDataChanged();
        }
         public void actualizarTabla2(String id){
            data = Controlador.Service.Compras.GestionCompra.FiltroSolAlmacen(id);
            fireTableDataChanged();
        }
        
        @Override
        public int getRowCount()
        {
            return data.size();
        }
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
        
        @Override
        public Object getValueAt(int row, int column)
        {   
                 switch(column){
                    case 0: return data.get(row).getIdOrdenCompra();
                    case 1: return data.get(row).getIdProducto();
                    case 2: return data.get(row).getPrecioUnitario();
                    case 3: return data.get(row).getCantidad();
                    default: return data.get(row).getSubTotal();
                   
                
            
        }
        } 
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        
        //Used by the JTable object to render different
        //functionality based on the data type
        @Override
        public Class getColumnClass(int c) {
           
            return getValueAt(0, c).getClass();
            
            
        }
    }
    
    
  
    
    public boolean valido(){
        
    boolean b = true;
    String n1="";
    String n2="";
    
    if(txtAlmacen.getText().isEmpty() || txtNomAlmacen.getText().isEmpty()){
            b = false;
           n1="Seleccione Almacen";
        }
    
     if(txtOrden.getText().isEmpty() ){
            b = false;
           n1="Seleccione Orden de Compra";
        }
    
         String rpta="";
         if (n1!="") rpta = rpta+ n1 + "\n";
         if (n2!="") rpta = rpta+ n2 + "\n";
          if (rpta!="")
         JOptionPane.showMessageDialog(null, "Errores: \n" + rpta );
    return b;
        
    
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblOrden = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        btnBuscar = new javax.swing.JButton();
        txtOrden = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        txtAlmacen = new javax.swing.JTextField();
        txtNomAlmacen = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtCapacidad = new javax.swing.JTextField();
        txtCantidad = new javax.swing.JTextField();

        setClosable(true);
        setTitle("Solicitud de Movimiento de OC");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tblOrden.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblOrden.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblOrdenMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblOrden);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 564, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ingresar campo"));

        jLabel1.setText("Orden Compra");

        btnBuscar.setText("Seleccionar Orden");
        btnBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnBuscarMouseClicked(evt);
            }
        });
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        txtOrden.setEditable(false);
        txtOrden.setEnabled(false);
        txtOrden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtOrdenActionPerformed(evt);
            }
        });
        txtOrden.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                txtOrdenInputMethodTextChanged(evt);
            }
        });
        txtOrden.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtOrdenKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtOrdenKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtOrdenKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(txtOrden, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(77, 77, 77)
                .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btnBuscar)
                    .addComponent(txtOrden, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setText("Amacen");

        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        jButton1.setText("Seleccionar Almacén");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        txtAlmacen.setEditable(false);
        txtAlmacen.setEnabled(false);

        txtNomAlmacen.setEditable(false);
        txtNomAlmacen.setEnabled(false);

        jLabel3.setText("IdAlmacen");

        txtCapacidad.setEditable(false);
        txtCapacidad.setEnabled(false);
        txtCapacidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCapacidadActionPerformed(evt);
            }
        });

        txtCantidad.setEditable(false);
        txtCantidad.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnAgregar)
                .addGap(137, 137, 137))
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtAlmacen, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(txtNomAlmacen))
                .addGap(83, 83, 83)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(117, 117, 117)
                        .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(txtAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNomAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(16, 16, 16))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAgregar)
                .addContainerGap(85, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblOrdenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblOrdenMouseClicked

    }//GEN-LAST:event_tblOrdenMouseClicked

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here
        SolicitudSeleccionarOrden sso= new SolicitudSeleccionarOrden(this);
        Main.getDesktop().add(sso);
        sso.setVisible(true);
         
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:
     if (valido())
     {      int resultado = JOptionPane.showConfirmDialog(this, "¿Desea aceptar la transacción?");
            if(resultado == JOptionPane.OK_OPTION){
               Double Cant=Controlador.Service.Compras.GestionCompra.obtenerCantOrden(txtOrden.getText());
                 if (Cant.doubleValue()>Double.parseDouble(txtCapacidad.getText()))  
                     
                     JOptionPane.showMessageDialog(null, "El almacen no tiene capacidad para guardar dichos productos");
                 else { 
                                
             
                List <Solicitud> ordenes=Controlador.Service.Compras.GestionCompra.obtenerSolicitudes(txtOrden.getText());
                List<ProductoxOrden> pxor = Controlador.Service.Compras.GestionCompra.FiltroSolAlmacen(txtOrden.getText());
               
                String idMov= Controlador.Service.Compras.GestionCompra.obtenerIdMov("Entrada");
                //List<SolicitudMovimiento> productos = Controlador.Service.Almacen.GestionAlmacenes.obtenerProdxSolicitudMovimiento(sm.getIdSolicitudMovimiento());

                Date fecha=new Date();
           
                        
                
                SolicitudMovimiento sm= new SolicitudMovimiento(idMov,Main.usu.getIdEmpleadoAdm(),txtAlmacen.getText(),"Entrada",fecha,"Ingreso de Orden de Compra","1","Externo");
                Controlador.Service.Almacen.GestionAlmacenes.agregarSolicitudMovimiento(sm);
          
                //idproducto 
                 ArrayList<ProdxSolicitudMovimiento> prodxsol = new  ArrayList<ProdxSolicitudMovimiento>();
                for(int i=0; i<pxor.size(); i++){
                                  
                  ProdxSolicitudMovimiento psm = new ProdxSolicitudMovimiento(pxor.get(i).getIdProducto(),idMov,Double.parseDouble(pxor.get(i).getCantidad().toString()));
                  prodxsol.add(psm);
                }
                  Controlador.Service.Almacen.GestionAlmacenes.agregarProdxSolMov(prodxsol, idMov, "Entrada");
                  
                  Controlador.Service.Compras.GestionCompra.actualizarEstado(txtOrden.getText());
                  tb2.actualizarTabla();
                  
                   JOptionPane.showMessageDialog(null, "Se envió solicitud de ingreso a Almacen");
                PanelSolOrdenAlm.this.dispose();
         }
               
               
                }    
                    
                     
            }     
    
              //if (flag !=0)  JOptionPane.showMessageDialog(null, "Se ingresaron los productos de "+cmbor+""); 
    
         
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        SolicitudSeleccionarAlmacen sso= new SolicitudSeleccionarAlmacen();
        Main.getDesktop().add(sso);
        sso.setVisible(true);
         tb2.actualizarTabla();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtOrdenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtOrdenActionPerformed
        // TODO add your handling code here:
          txtOrden.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {

         if (Integer.parseInt(txtOrden.getText())>0){
                             tb.actualizarTabla();
                        }       
     }
});
    }//GEN-LAST:event_txtOrdenActionPerformed

    private void txtOrdenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOrdenKeyPressed
        // TODO add your handling code here:
        txtOrden.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {

         if (Integer.parseInt(txtOrden.getText())>0){
                             tb.actualizarTabla();
                        }       
     }
});
    }//GEN-LAST:event_txtOrdenKeyPressed

    private void txtOrdenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOrdenKeyTyped
        // TODO add your handling code here:
          txtOrden.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {

         if (Integer.parseInt(txtOrden.getText())>0){
                             tb.actualizarTabla();
                        }       
     }
});
    }//GEN-LAST:event_txtOrdenKeyTyped

    private void txtOrdenKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOrdenKeyReleased
        // TODO add your handling code here:
            txtOrden.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {

         if (Integer.parseInt(txtOrden.getText())>0){
                             tb.actualizarTabla();
                        }       
     }
});
    }//GEN-LAST:event_txtOrdenKeyReleased

    private void txtCapacidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCapacidadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCapacidadActionPerformed

    private void btnBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBuscarMouseClicked
        // TODO add your handling code here:
          tb2.actualizarTabla();
    }//GEN-LAST:event_btnBuscarMouseClicked

    private void txtOrdenInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_txtOrdenInputMethodTextChanged
        // TODO add your handling code here:
        if (!txtOrden.getText().isEmpty())
        tb2.actualizarTabla();
    }//GEN-LAST:event_txtOrdenInputMethodTextChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JTable tblOrden;
    public static javax.swing.JTextField txtAlmacen;
    public static javax.swing.JTextField txtCantidad;
    public static javax.swing.JTextField txtCapacidad;
    public static javax.swing.JTextField txtNomAlmacen;
    public static javax.swing.JTextField txtOrden;
    // End of variables declaration//GEN-END:variables
}
